<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //冒泡排序
        var arr = [5,4,6,8,9,7,3,1,2];
        for(var i = 0;i <= arr.length - 1;i++){ //外层循环躺数
            for(var j = 0;j <= arr.length - i - 1;j++){ //里面的循环 每一趟的交换次数
                //内部交换2个变量 前一个和后面一个数组相比较
                if(arr[j] > arr[j+1]){
                    var num = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = num;
                }
            }
        }
        console.log(arr);
    </script>
</head>
<body>
    
</body>
</html>